import {useLocation} from "umi";
import { PageContainer } from '@ant-design/pro-components';
import {getInterviewById,editInterviewApi} from "@/services/interview"
import {useState,useEffect} from 'react';
import InterviewForm from "./components/interviewForm"
import {useNavigate} from "umi"
import {message} from "antd"
export default function EditInterview() {
  const [interviewInfo,setInterviewInfo] = useState({});
  const navigator = useNavigate()

  const location = useLocation();
  const id = location.state?.id;
  useEffect(()=>{
    // 请求数据
    getInterviewById(id).then(res=>{
      console.log(res)
      setInterviewInfo(res.data)
    })
  },[])
  function submit(tar){
    console.log(tar)
    console.log(interviewInfo)
    editInterviewApi(interviewInfo._id,tar).then(res=>{
      navigator('/interview/interviewList')
      message.success('编辑成功')
    })
  }
  console.log(id)
  return (
    <PageContainer header={{
      breadcrumb: {
        items: [
          {
            title: '面试题',
          },
          {
            title: '编辑题目',
          },
        ],
      },
    }} >
    <InterviewForm initData={interviewInfo} type="edit" submit={submit}/>
    </PageContainer>
  )
}
